<?php
// @formatter:off
/**
 * @file finalize.php
 * @author Alejandro Dario Simi
 * @date $Date: 2013-06-07 02:16:25 +0000 (Fri, 07 Jun 2013) $
 *
 * $Id: finalize.php 71 2013-06-07 02:16:25Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/tags/wcomix-1.0-BETA1/install/steps/finalize.php $
 */
// @formatter:on

require_once "{$wcPaths["includes-directory"]}/tools.php";

if(defined('__INSTALLER__')) {
	if(!is_readable($wcPaths['install-tmps']['cron-check'])) {
		file_put_contents($wcPaths['install-tmps']['cron'], "<?php echo __FILE__; ?>");
		file_put_contents($wcPaths['install-tmps']['cron-check'], "<?php echo __FILE__; ?>");

		$isOkToContinue = true;
		$isOkToReload = true;
		$isFastReload = true;
	} elseif(is_readable($wcPaths['install-tmps']['cron'])) {
		echo "\t\t\t\t<p>[FL:wcomix cron was not run.]</p>\n";
		echo "\t\t\t\t<p>Before you can proceed, wcomix cron must be run. Please run the next command in you system:\n";
		if(DIRECTORY_SEPARATOR == "\\") {
			$binpath = getBinaryFullPath("php");
			echo "\t\t\t\t\t<pre class=\"Code\"";
			if(!$binpath) {
				echo " title=\"php path is not added to environment variable %PATH%\"> php.exe ";
			} else {
				echo "> {$binpath} ";
			}
			echo WCSanitizer::SystemPath("{$wcPaths['cron-directory']}/cron.php")."</pre>\n";
		} else {
			echo "\t\t\t\t\t<pre class=\"Code\">sudo -u ".exec('whoami')." php {$wcPaths['cron-directory']}/cron.php</pre>\n";
		}
		echo "\t\t\t\t</p>\n";
		echo "\t\t\t\t<p>After running wcomix's cron, press the next button.</p>\n";
		echo "\t\t\t\t<p><input type=\"button\" value=\"Retry\" onclick=\"location.reload();return false;\"/></p>\n";

		$isOkToContinue = false;
		$isOkToReload = false;
	} else {
		$iDirName = basename(dirname(dirname(__FILE__)));

		echo "\t\t\t\t<p>[OK:System installation was a success.]</p>\n";
		echo "\t\t\t\t<p>Press the next button to visit the new site.</p>\n";
		echo "\t\t\t\t<p><input type=\"button\" value=\"Visit new site\" onclick=\"window.location='".str_replace("/{$iDirName}", "", $_SERVER["REQUEST_URI"])."';return false;\"/></p>\n";
		echo "\t\t\t\t<p>It's recommened to disable installation process by setting the default variable '{VA:\$wcDefaults['installed']}' to true in 'local.conf.php'</p>\n";

		$isOkToContinue = false;
		$isOkToReload = false;
		$isOkToRemoveSteps = true;
	}
}
?>